{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Solution:\n",
    "    def uniquePathsWithObstacles(self, obstacleGrid: List[List[int]]) -> int:\n",
    "        obs = obstacleGrid\n",
    "        rows = len(obs)\n",
    "        cols = len(obs[0])\n",
    "        path = [[0]*cols for i in range(rows)]\n",
    "        if(obs[0][0] == 1):\n",
    "            return 0\n",
    "        path[0][0] = 1\n",
    "        for i in range(1, cols):\n",
    "            if(obs[0][i] == 0):\n",
    "                path[0][i] = path[0][i-1]\n",
    "            else:\n",
    "                break\n",
    "        for j in range(1, rows):\n",
    "            if(obs[j][0] == 0):\n",
    "                path[j][0] = path[j-1][0]\n",
    "            else:\n",
    "                break\n",
    "        for r in range(1,rows):\n",
    "            for c in range(1, cols):\n",
    "                if(obs[r][c] == 0):\n",
    "                    path[r][c] = path[r][c-1] + path[r-1][c]\n",
    "                else:\n",
    "                    path[r][c] = 0\n",
    "        return path[rows-1][cols-1]\n",
    "                    \n",
    "                \n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Dp solution , very simple!\n",
    "class Solution:\n",
    "    def uniquePathsWithObstacles(self, obstacleGrid: List[List[int]]) -> int:\n",
    "        obs = obstacleGrid\n",
    "        rows = len(obs) + 1\n",
    "        cols = len(obs[0]) + 1\n",
    "        path = [[0]*cols for i in range(rows)]\n",
    "        path[0][1] = 1 # (0,1)为入口\n",
    "        for r in range(1,rows):\n",
    "            for c in range(1, cols):\n",
    "                if(obs[r-1][c-1] == 0):\n",
    "                    path[r][c] = path[r][c-1] + path[r-1][c]\n",
    "                else:\n",
    "                    path[r][c] = 0\n",
    "        return path[rows-1][cols-1]"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
